/*
 * @Date: 2025-06-17 15:26:52
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-10-05 16:23:19
 * @FilePath: \corpus\src\pages\Home\component\List.tsx
 */
import { EllipsisOutlined } from '@ant-design/icons';
import { history, useModel } from '@umijs/max';
import { Badge, Button, Col, Dropdown, Popconfirm, Tag, Tooltip } from 'antd';
import hooks from '../hooks/useHooks';
import knowledge from '../img/knowledge.svg';
import styles from './index.less';
const Status = (props) => {
  const { releaseStatus } = props;
  return (
    <>
      {releaseStatus === 1 ? (
        <Badge classNames={styles.colorName} text={'状态: 已发布'} status="success" />
      ) : (
        <Badge classNames={styles.colorName} text={'状态: 未发布'} status="warning" />
      )}
    </>
  );
};
const List = (props: {
  item: any;
  handleClick?: (val: any) => void;
  handleUp?: (val: any) => void;
  show?: boolean;
  style?: any;
  key?: number;
}) => {
  const { item } = props;
  const {
    setCorpuVisible,
    setApplyVisible,
    getLligentAgent,
    formCorpus,
    setDetail,
    setType,
    setAngentVisible,
    formApply,
    setDisabled,
  } = hooks.useContainer();
  const { getRole } = useModel('useUser', (model) => {
    return {
      getRole: model.getRole,
    };
  });
  const items: any[] = [
    getRole('admin:upload') && {
      label: (
        <div
          onClick={(e) => {
            formCorpus.resetFields();
            setType(item.type);
            setDetail({ ...item });
            setCorpuVisible(true);
            e.stopPropagation();
          }}
        >
          编辑
        </div>
      ),
      key: '0',
    },
    // {
    //   label: (
    //     <Popconfirm
    //       title="知识库"
    //       description={`确认 ${item.releaseStatus === 0 ? '发布？' : '取消发布？'}`}
    //       onConfirm={(e) => {
    //         props?.handleUp?.({ ...item, releaseStatus: item.releaseStatus === 1 ? 0 : 1 });
    //         e?.stopPropagation();
    //       }}
    //       onCancel={(e) => {
    //         e?.stopPropagation();
    //       }}
    //       okText="确认"
    //       cancelText="取消"
    //     >
    //       <div
    //         onClick={(e) => {
    //           e?.stopPropagation();
    //         }}
    //       >{`${item.releaseStatus === 0 ? '发布' : '取消发布'}`}</div>
    //     </Popconfirm>
    //   ),
    //   key: '1',
    // },
    {
      type: 'divider',
      key: '2',
    },
    getRole('admin:upload') && {
      label: (
        <Popconfirm
          title="知识库"
          description={`确认 ${item.status === 0 ? '启用知识库？' : '禁用知识库？'}`}
          onConfirm={(e) => {
            props?.handleUp?.({ ...item, status: item.status === 1 ? 0 : 1 });
            e?.stopPropagation();
          }}
          onCancel={(e) => {
            e?.stopPropagation();
          }}
          okText="确认"
          cancelText="取消"
        >
          <div
            onClick={(e) => {
              e.stopPropagation();
            }}
          >{`${item.status === 0 ? '启用知识库' : '禁用知识库'}`}</div>
        </Popconfirm>
      ),
      key: '3',
    },
    item.type === 'gr' &&
      !getRole('admin:upload') && {
        label: (
          <span
            onClick={() => {
              getLligentAgent.run();

              setDetail({
                ...item,
                intelligentId: item.intelligentId,
              });
            }}
          >
            授权智能体
          </span>
        ),
        key: '5',
      },

    getRole('admin:upload') && {
      label: (
        <span
          onClick={() => {
            if (item.type === 'bm') {
              history.push(
                {
                  pathname: '/dept-home/list/knowledge-content',
                },
                {
                  dsCode: item.bailianKnowledgeId,
                },
              );
            } else if (item.type === 'gr') {
              history.push(
                {
                  pathname: '/person-home/list/knowledge-content',
                },
                {
                  dsCode: item.bailianKnowledgeId,
                },
              );
            } else if (item.type === 'gg') {
              history.push(
                {
                  pathname: '/common-home/list/knowledge-content',
                },
                {
                  dsCode: item.bailianKnowledgeId,
                },
              );
            } else {
              history.push(
                {
                  pathname: '/resourceManagement/list/knowledge-content',
                },
                {
                  dsCode: item.bailianKnowledgeId,
                },
              );
            }
          }}
        >
          知识库内容
        </span>
      ),
      key: '6',
    },
    // (item.type === 'gr' || item.type === 'bm') && {
    //   label: (
    //     <span
    //       onClick={() => {
    //         setDetail({ ...item });
    //         setType(item.type);
    //         setDisabled(false);
    //         setApplyVisible(true);
    //       }}
    //     >
    //       知识库上传申请
    //     </span>
    //   ),
    //   key: '6',
    // },
  ];
  return (
    <Col md={24} lg={12} xl={8} xxl={6} className={styles.contentWrap}>
      <div
        onClick={(e) => {
          props?.handleClick?.(item);
          e.stopPropagation();
          e.preventDefault();
        }}
        className={styles.content}
        style={props?.style}
      >
        <Badge.Ribbon
          text={item.status === 1 ? '已启用' : '已禁用'}
          color={item.status === 1 ? 'green' : 'red'}
        >
          <div
            style={{
              height: '160.0px',
              display: 'flex',
              flexDirection: 'column',
              justifyContent: 'space-between',
            }}
          >
            <div className={styles.contentTitle}>
              <div className={styles.contentImg}>
                <img style={{ width: '50.0px', height: '50.0px' }} src={knowledge} />
              </div>

              <div className={styles.contentName}>
                <ul>
                  <li>{item.name}</li>
                  <Tooltip title={item.knowledgeDescribe}>
                    <li>{item.knowledgeDescribe}</li>
                  </Tooltip>
                </ul>
              </div>
            </div>

            <div className={styles.contentItem}>
              {item.intelligentNames && (
                <span style={{ marginLeft: '0.0px' }}>
                  {item?.intelligentNames
                    ? item?.intelligentNames?.split(',').map((item: any, index: number) => {
                        return (
                          <Tag key={index} color="success">
                            {item}
                          </Tag>
                        );
                      })
                    : ''}
                </span>
              )}
            </div>
            <div className={styles.contentItem}>创建日期：{item.createTime}</div>
            <div className={styles.contentItem}>
              <Tooltip title={item.deptName}>
                <span className={styles.hidden}>归属部门：{item.deptName}</span>
              </Tooltip>
            </div>
            <div className={styles.contentItem}>
              <span>
                类型：
                {item.type === 'gr'
                  ? '个人'
                  : item.type === 'bm'
                  ? '部门'
                  : item.type === 'cj'
                  ? '场景'
                  : item.type === 'jc'
                  ? '基础'
                  : '公共'}
                知识库
              </span>
              {/* <span style={{ marginLeft: '10.0px' }}>
              <Status releaseStatus={item.releaseStatus} />
            </span> */}
              <span style={{ marginLeft: '5.0px' }}>创建人：{item.createUserName}</span>

              {props?.show && (
                <span
                  onClick={(e) => e.stopPropagation()}
                  style={{ marginLeft: '20.0px', paddingRight: '10.0px' }}
                >
                  <Dropdown menu={{ items }}>
                    <Button
                      onClick={(e) => {
                        e.preventDefault();
                        e.stopPropagation();
                      }}
                      color="default"
                      variant="filled"
                      size="small"
                    >
                      <EllipsisOutlined style={{ color: 'rgba(0,0,0,0.3)' }} />
                    </Button>
                  </Dropdown>
                </span>
              )}
            </div>
          </div>
        </Badge.Ribbon>
      </div>
    </Col>
  );
};
List.defaultProps = {
  show: true,
};
export default List;
